import numpy as np
import pandas as pd
import matplotlib as mpl
import matplotlib.pyplot as plt
import seaborn as sns

plt.rcParams['font.sans-serif'] = ['SimHei']  # 用来正常显示中文标签
plt.rcParams['axes.unicode_minus'] = False  # 用来正常显示负号

pv_uv_daily = pd.read_csv(r'..\taobao\data\pv_uv_daily.csv', index_col=0, encoding="utf_8_sig")
pv_uv_hour = pd.read_csv(r'..\taobao\data\pv_uv_hour.csv', index_col=0, encoding="utf_8_sig")

print(pv_uv_daily)
month = list(pv_uv_daily.index)
pv_daily = list(pv_uv_daily.pv_daily)
uv_daily = list(pv_uv_daily.uv_daily)

hour = list(pv_uv_hour.index)
pv_hour = list(pv_uv_hour.pv_hour)
uv_hour = list(pv_uv_hour.uv_hour)
print(pv_uv_hour)


def fig_uv_pv_daily(time=month, pv=pv_daily, uv=uv_daily):
    # 画图
    fig = plt.figure(figsize=(30, 10))
    # 左轴
    ax1 = fig.add_subplot(111)
    ax1.plot(time, pv, color='g', alpha=0.5)
    ax1.set_xlabel('月份', fontsize=28)
    ax1.set_ylabel('日活pv', fontsize=18, color='g')

    # 右轴
    ax2 = ax1.twinx()
    ax2.plot(time, uv, color='b')
    ax2.set_ylabel('访问人数uv', fontsize=18, color='b')

    for x, y in list(zip(time, pv)):
        plt.text(x, y + 0.05, '%0.2f' % y, ha='center', va='bottom')

    for x, y in list(zip(time, uv)):
        plt.text(x, y - .05, '%0.2f' % y, ha='center', va='bottom')

    # 标题
    plt.title('日活及点击率趋势')
    plt.savefig('./picture/日活及点击率趋势.svg')
    plt.show()


def fig_uv_pv_hour(time=hour, pv=pv_hour, uv=uv_hour):
    # 画图
    fig = plt.figure(figsize=(31, 10))
    # 左轴
    ax1 = fig.add_subplot(111)
    ax1.plot(time, pv, color='g', alpha=0.5)
    ax1.set_xlabel('时刻', fontsize=28)
    ax1.set_ylabel('日活pv', fontsize=18, color='g')

    # 右轴
    ax2 = ax1.twinx()
    ax2.plot(time, uv, color='b')
    ax2.set_ylabel('访问人数uv', fontsize=18, color='b')

    for x, y in list(zip(time, pv)):
        plt.text(x, y + 0.05, '%0.2f' % y, ha='center', va='bottom')

    for x, y in list(zip(time, uv)):
        plt.text(x, y - 0.05, '%0.2f' % y, ha='center', va='bottom')

    # 标题
    plt.title('日内点击率趋势')
    plt.savefig('./picture/日内点击率趋势.svg')
    plt.show()


fig_uv_pv_daily()
fig_uv_pv_hour()
